<?php
/**
 * Created by leiying
 * Date: 2017/8/30
 * Time: 18:01
 */

/**按照位置id分类广告，并以特定键值命名
 * @param $name键值
 * @param $position_id
 * @param $lists 广告列表
 * @return array
 * @author leiying
 */
function get_ad_info($name,$position_id,$lists){
    $arr = array();
    foreach($lists as &$value){
        if($position_id == $value['position_id']){
            $value['ad_img'] = GZ_Api::get_url($value['ad_link']);
            unset($value['ad_link']);
            $arr[] = $value;
        }
    }
    return $arr;
}

/**根据类型id获取资讯
 * @param $type_id 资讯类型id
 * @author leiying
 */
function get_news($type_id){
    $sql = "SELECT `id` news_id,`title` FROM km_article WHERE `cid`=".$type_id." ORDER BY `addtime` DESC LIMIT 5";
    $res = $GLOBALS['db']->getAll($sql);
    foreach($res as &$v){
        $v['url'] = '';
    }
    return $res;
}

/**获取精品推荐产品
 * @return mixed
 * @author leiying
 */
function get_best_goods(){
    $sql = "SELECT `goods_id`,`goods_name`,`goods_cover`,`shop_price` FROM km_goods WHERE `is_best`=1 ORDER BY `add_time` DESC";
    $res = $GLOBALS['db']->getAll($sql);
    foreach($res as &$v){
        $v['goods_cover'] = GZ_Api::get_url($v['goods_cover']);
        $v['shop_price'] = $v['shop_price']?"￥".$v["shop_price"]:"0";
    }
    return $res;
}










